//
//  ViewController.m
//  28-UIViewAnimation(2)
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 DM.C. All rights reserved.
//

//UIViewAnimationOptionLayoutSubviews//进行动画时布局子控件
//UIViewAnimationOptionAllowUserInteraction//进行动画时允许用户交互
//UIViewAnimationOptionBeginFromCurrentState//从当前状态开始动画
//UIViewAnimationOptionRepeat//无限重复执行动画
//UIViewAnimationOptionAutoreverse//执行动画回路
//UIViewAnimationOptionOverrideInheritedDuration//忽略嵌套动画的执行时间设置
//UIViewAnimationOptionOverrideInheritedCurve//忽略嵌套动画的曲线设置
//UIViewAnimationOptionAllowAnimatedContent//转场：进行动画时重绘视图
//UIViewAnimationOptionShowHideTransitionViews//转场：移除（添加和移除图层的）动画效果
//UIViewAnimationOptionOverrideInheritedOptions//不继承父动画设置
//UIViewAnimationOptionCurveEaseInOut//时间曲线，慢进慢出（默认值）
//UIViewAnimationOptionCurveEaseIn//时间曲线，慢进
//UIViewAnimationOptionCurveEaseOut//时间曲线，慢出
//UIViewAnimationOptionCurveLinear//时间曲线，匀速
//UIViewAnimationOptionTransitionNone//转场，不使用动画
//UIViewAnimationOptionTransitionFlipFromLeft//转场，从左向右旋转翻页
//UIViewAnimationOptionTransitionFlipFromRight//转场，从右向左旋转翻页
//UIViewAnimationOptionTransitionCurlUp//转场，下往上卷曲翻页
//UIViewAnimationOptionTransitionCurlDown//转场，从上往下卷曲翻页
//UIViewAnimationOptionTransitionCrossDissolve//转场，交叉消失和出现
//UIViewAnimationOptionTransitionFlipFromTop//转场，从上向下旋转翻页
//UIViewAnimationOptionTransitionFlipFromBottom//转场，从下向上旋转翻页



#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic, strong) UIButton *animationButtonTwo;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
       }
#pragma mark - 一般我们在这个方法了里写动画
- (void)viewDidAppear:(BOOL)animated {
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
    _animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
    
    /**
     * 参数1:
     * 参数2:
     * 参数3:0.1 ~~ 1.0 数值越小, 阻力越小, 数值越大, 阻力越大
     * 参数4:速度
     * 参数5:动画效果选项
     */
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
        _animationView.dm_width = 50;
        _animationView.dm_height = 50;
        _animationView.backgroundColor = [UIColor cyanColor];
        _animationView.layer.cornerRadius = 25;
    } completion:^(BOOL finished) {
        NSLog(@"动画结束");
    }];
    
    self.animationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_animationButton];
    self.animationButton.frame = CGRectMake(100, 100, 200, 200);
    _animationButton.backgroundColor = [UIColor greenColor];
    [_animationButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.animationButtonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    self.animationButtonTwo.frame = CGRectMake(100, 100, 200, 200);
    _animationButtonTwo.backgroundColor = [UIColor blueColor];
    [_animationButtonTwo addTarget:self action:@selector(clickButtonTwo:) forControlEvents:UIControlEventTouchUpInside];
    

}
- (void)clickButton:(UIButton *)button {
    /**
     * 参数1:需要执行动画的View
     * 参数2:持续时间
     * 参数3:动画效果
     */
//    [UIView transitionWithView:_animationButton duration:5 options:UIViewAnimationOptionTransitionCurlUp animations:^{
//        _animationButton.dm_width = 100;
//        _animationButton.dm_height = 100;
//    } completion:^(BOOL finished) {
//        // 动画里面可以嵌套动画
//        [UIView animateWithDuration:5 animations:^{
//             _animationButton.dm_width = 200;
//        _animationButton.dm_height = 200;
//        }];
//    }];
    
    [UIView transitionFromView:_animationButton toView:_animationButtonTwo duration:2 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
    }];
    
}
- (void)clickButtonTwo:(UIButton *)button {
    // toView added to fromView.superview, fromView removed from its superview
    // 解释: toView会被添加到fromView的父视图上, 然后fromView被从父视图移除
    [UIView transitionFromView:_animationButtonTwo toView:_animationButton duration:2 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
